﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Web.Mvc;

namespace Matriculex.Testes
{
    public static class Extensoes
    {
        public static string Prepara(this string str)
        {
            return str.ToLower().Trim().Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "");
        }

        public static List<TResult> Map<T, TResult>(this List<T> list, Func<T, TResult> mapFunc)
        {
            List<TResult> mappedList = new List<TResult>();
            list.ForEach(elemento => mappedList.Add(mapFunc(elemento)));
            return mappedList;
        }
        public static void ForEach<T>(this IList<T> list, Action<T> function)
        {
            foreach (T item in list)
            {
                function(item);
            }
        }

        public static void ForEach<T>(this IEnumerable<T> list, Action<T> function)
        {
            foreach (T item in list)
            {
                function(item);
            }
        }

        public static List<T> Fill<T>(this List<T> list, T element, int nTimes)
        {
            if (nTimes < 0) throw new ArgumentException();
            while (nTimes-- > 0)
                list.Add(element);
            return list;
        }
       
    }
}
